package com.jqr.activity.listviewdemo.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.jqr.activity.listviewdemo.R;
import com.jqr.activity.listviewdemo.model.Article;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SimpleActivity extends AppCompatActivity {
    private ListView listView;
    private List<Map<String, Object>> mapList;
    private  Map<String,Object> map;
    private  int[] imgs={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);

        listView=findViewById(R.id.simpleAdapterListView);

        mapList=new ArrayList<Map<String, Object>>();

        for (int i = 0; i < 10; i++) {
            map=new HashMap<>();
            map.put("img",imgs[i%imgs.length]);
            map.put("title","这是标题"+i+1);
            map.put("content","这是内容"+i+1);
            mapList.add(map);
        }
        SimpleAdapter simpleAdapter=new SimpleAdapter(
                this,
                    mapList,
                    R.layout.list_item,
                    new String[]{"img","title","content"},
                    new int[]{R.id.ivImg,R.id.tvTitle,R.id.tvContent}
                );
        listView.setAdapter(simpleAdapter);
    }
}